package com.singfan.common.util;

import com.singfan.common.SingFanException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Properties文件工具类
 * Author: HanSongHe
 * Date: 2015-07-27 15:23
 * Desc:
 */
public class PropertiesUtil {
    /**
     * 读取Properties文件内容
     * @param fileName Properties文件名
     * @return Properties文件内容
     */
    public static Properties getProperties(String fileName){
        InputStream is = null;
        try {
            Properties properties = new Properties();
            is = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName);
            properties.load(is);
            return properties;
        }
        catch (IOException ex) {
            throw new SingFanException(String.format("PropertiesUtil.getProperties() error: %s !", ex.getMessage()));
        }
        finally {
            if (is != null) {
                try {
                    is.close();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
